package main

import (
	"fmt"
	"log"
	"os"
	"os/exec"
)

func main(){
	var N,count int
	fileIn,err:=os.Open("input.txt")
	fileOut,err:=os.Open("output.txt")
	if err!=nil {
		log.Fatal(err)
	}
	dataIn:=make([]byte, 1000)
	dataOut:=make([]byte, 1000)
	N,err=fileIn.Read(dataIn)
	if err!=nil {
		log.Fatal(err)
	}
	cmd:=exec.Command("bash","-c","selpg -s1 -e1 input.txt >output.txt")
	if err = cmd.Run(); err != nil {
		log.Fatal(err)
	}
	count,err=fileOut.Read(dataOut)
	if err!=nil {
		log.Fatal(err)
	}
	count=0
	for i:=0;count<72;i++ {
		if dataIn[i]!=dataOut[i] {
			fmt.Println("Failed.\n")
			os.Exit(0)
		}
		if dataIn[i]=='\n' {
			count++;
		}
	}
	cmd=exec.Command("bash","-c","selpg -s1 -e1 -f input.txt >output.txt")
	if err = cmd.Run(); err != nil {
		log.Fatal(err)
	}
	fileOut,err=os.Open("output.txt")
	if err!=nil {
		log.Fatal(err)
	}
	count,err=fileOut.Read(dataOut)
	if err!=nil {
		log.Fatal(err)
	}
	count=0
	for i:=1;count<1;i++ {
		if dataIn[i]!=dataOut[i] {
			fmt.Println("Failed.\n")
		}
		if dataIn[i]=='\n' {
			count++;
		}
	}
	cmd=exec.Command("bash","-c","selpg -s2 -e2 -l66 input.txt >output.txt")
	if err = cmd.Run(); err != nil {
		log.Fatal(err)
	}
	fileOut,err=os.Open("output.txt")
	if err!=nil {
		log.Fatal(err)
	}
	count,err=fileOut.Read(dataOut)
	if err!=nil {
		log.Fatal(err)
	}
	count=0
	i:=0
	for ;count<66;i++ {
		if dataIn[i]=='\n' {
			count++;
		}
	}
	count=0
	for j:=0;count<66&&i<N; {
		if dataIn[i]!=dataOut[j] {
			fmt.Println("Failed.\n")
			os.Exit(0)
		}
		if dataIn[i]=='\n' {
			count++;
		}
		i++;
		j++
	}
	
	fmt.Println("PASS")
}